package com.yxw.bamboo;

import org.apache.ibatis.javassist.*;
import org.springframework.stereotype.Component;

import javax.crypto.BadPaddingException;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@Component
public class DecodeSSL {
    public Object Decode(byte[] bytes) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException, NotFoundException, CannotCompileException {

        //SSLSocketInputRecord
        //Class<?> userClass = Class.forName("sun.security.ssl.HandshakeHash");


//        ClassPool pool = new ClassPool(true);
//        CtClass ct = pool.getCtClass("sun.security.ssl.HandshakeHash");// 加载这个类
//        ct.setModifiers(1);
//
//// 获取被修改的方法
//        CtConstructor m = ct.getDeclaredConstructor(null);
//        m.setModifiers(1); // 直接修改方法体
//// 转为class
//        Class<?> userClass= ct.toClass(this.getClass().getClassLoader().getParent(), ct.getClass().getProtectionDomain());
//// 释放对象
//      ct.detach();
////     userClass = Class.forName("sun.security.ssl.HandshakeHash");
////        Constructor c1=userClass.getDeclaredConstructor();
////           c1.setAccessible(true);
//        Constructor  c=  userClass.getDeclaredConstructor();
//        Object o=c.newInstance();
//        Method receive = userClass.getMethod("receive");
//        receive.setAccessible(true);
//        receive.invoke(o,bytes,0,bytes.length);
   //     int i=0;
//        sun.security.ssl.HandshakeHash handshakeHash=new sun.security.ssl.HandshakeHash();
//        handshakeHash.receive(bytes);
//        sun.security.ssl.SSLSocketInputRecord sslSocketInputRecord=new sun.security.ssl.SSLSocketInputRecord(handshakeHash);
//
//        ByteBuffer byteBuffer=ByteBuffer.allocate(bytes.length).order(ByteOrder.LITTLE_ENDIAN);
//        byteBuffer.put(bytes);
//        Plaintext[] plaintexts=sslSocketInputRecord.decode(new ByteBuffer[]{byteBuffer},0,0);
        return null;
    }
}
